import 'package:cbec_app/components/base/base_image.dart';
import 'package:cbec_app/components/base/base_interactive.dart';
import 'package:cbec_app/components/base/base_nav_bar.dart';
import 'package:cbec_app/components/base/base_page.dart';
import 'package:cbec_app/components/common/common_style.dart';
import 'package:cbec_app/utils/Tools.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:intl/intl.dart';


//销售数据
class SalesData extends StatelessWidget {
  SalesData({super.key});

  final DateFormat format = DateFormat('yyyy-MM-dd');

  @override
  Widget build(BuildContext context) {
    return BasePage(
      title: "销售数据",
      iconType: IconType.back,
      bgImageUrl: "sales_data_bg.png",
      bgColor: Tools.fromHex("#F3F5F7"),
      bgImgFit: BoxFit.fitWidth,
      bodyColor: Colors.transparent,
      children: [
        Container(
          margin: EdgeInsets.only(top: 74.w, left: 18.w),
          child: Text("数据统计详情",
              style:
                  setTextStyle(24, FontWeight.bold, Tools.fromHex("#333333"))),
        ),
        Container(
          margin: EdgeInsets.only(top: 4.w, left: 18.w),
          child: Text("注.余额均只统计已完成的订单金额",
              style: setTextStyle(
                  14, FontWeight.normal, Tools.fromHex("#999999"))),
        ),
        Container(
          margin: EdgeInsets.only(left: 18.w, top: 20.w, right: 18.w),
          decoration: border_radis(Colors.white),
          child: Column(
            children: [
              SizedBox(
                height: 31.h,
              ),
              Text("累计总销售额(元)",style: setTextStyle(12, FontWeight.normal, Tools.fromHex("#999999"))),
              SizedBox(
                height: 5.h,
              ),
              Text("52,150",style: setTextStyle(24, FontWeight.bold, Tools.fromHex("#333333"))),
              SizedBox(
                height: 10.h,
              ),
              BaseInteractive(
                onClick: () => {_show(context)},
                childWidget: Container(
                  width: 84.w,
                  padding: EdgeInsets.fromLTRB(10.w, 2.w, 10.w, 2.w),
                  decoration:
                      border_radis(Tools.fromHex("#F3F5F7"), radiusValue: 20),
                  child: Row(
                    children: [
                      Text("时间区间",style: setTextStyle(12, FontWeight.normal, Tools.fromHex("#333333"))),
                      BaseImage(url: "promotions_xl.png", width: 14, height: 14)
                    ],
                  ),
                ),
              ),
              SizedBox(
                height: 5.h,
              ),
              Text("2022/09/15 ～ 2022/10/14",style: setTextStyle(12, FontWeight.normal, Tools.fromHex("#999999"))),
              SizedBox(
                height: 30.h,
              ),
              Container(
                decoration: top_gary_border,
                margin: EdgeInsets.only(left: 22.w, right: 22.w),
              ),
              SizedBox(
                height: 20.h,
              ),
              Container(
                padding: EdgeInsets.only(left: 11.w, right: 11.w),
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [Text("累计邀请客户(人)",style: setTextStyle(12, FontWeight.normal, Tools.fromHex("#999999"))), Text("100",style: setTextStyle(15, FontWeight.bold, Tools.fromHex("#333333")))],
                ),
              ),
              SizedBox(height: 14.h),
              Container(
                padding: EdgeInsets.only(left: 11.w, right: 11.w,bottom: 35.w),
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [Text("累计订单数(笔)",style: setTextStyle(12, FontWeight.normal, Tools.fromHex("#999999"))), Text("100",style: setTextStyle(15, FontWeight.bold, Tools.fromHex("#333333")))],
                ),
              ),
            ],
          ),
        )
      ],
    );
  }


  //日期范围选择器
  void _show(BuildContext context) async {
    DateTime firstDate = DateTime(2021, 1, 1);
    DateTime lastDate = DateTime.now();
    DateTime start = lastDate.add(const Duration(days: -8));
    DateTime end = lastDate.add(const Duration(days: -2));
    DateTimeRange? range = await showDateRangePicker(
        context: context,
        firstDate: firstDate,
        lastDate: lastDate,
        initialDateRange: DateTimeRange(
          start: start,
          end: end,
        ),
        saveText: "确定",
        );
    if (range != null) {
      print("${format.format(range.start)} ~ ${format.format(range.end)}");
    }
  }

}
